﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using AspNetCs.Model;
using AspNetCs.Bll;

public partial class Agent_ManageSiteConfig : Admin_BasePage
{
    protected PartSiteConfigBLL bll = CreatePartSiteConfig_BLL.CreateNew;
    protected PartSiteConfigModel model = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        IsExitAgent();
        if(!IsPostBack)
        {
            model=bll.GetModel(AgentInfo.LoginPro, AgentInfo.LoginCity);
            txtLogo.Text = model.LogoURL;
            txtManagerEmail.Text = model.ManagerEmail;
            txtManagerName.Text = model.MangerName;
            txtName.Text = model.SiteName;
            //txtQQ.Text = model.SiteQQ;
            txtVersion.Text = model.Version;
            ViewState["model"] = model;
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if(ViewState["model"]!=null)
        {
            model = ViewState["model"] as PartSiteConfigModel;
            model.LogoURL = txtLogo.Text;
            model.ManagerEmail = txtManagerEmail.Text;
            model.MangerName = txtManagerName.Text;
            model.SiteName = txtName.Text;
            model.SiteQQ = "";
            model.Version = txtVersion.Text;
            model.Province = AgentInfo.LoginPro;
            model.City = AgentInfo.LoginCity;
            if (model.Province == 0 || model.City == 0)
            {
                //bll.AddSiteConfig(model);
            }
            else
            {
                if (bll.IsExistSiteConfig(model.Province, model.City))
                {
                    bll.UpdateSiteConfig(model); 
                }
                else
                {
                    bll.AddSiteConfig(model);
                }
                
            }
        }
    }
}
